******************
******************
*Replication Data for "White Constituents and Congressional Voting"
*Eric R. Hansen
*Forthcoming, American Politics Research
*Analysis conducted using Stata 16.1
*Send questions/comments to ehansen4@luc.edu
******************
******************


***************
*House data and code to replicate Figure 1a and Tables 1, A1, A3, A5, and A7
***************
clear

*set your own working directory
cd "C:\ "

import delimited "house.csv"
gen south = 0
replace south = 1 if state_abbrev == "AR" | state_abbrev == "TX" | state_abbrev == "LA" | state_abbrev == "MS" | state_abbrev == "AL" | state_abbrev == "TN" | state_abbrev == "GA" | state_abbrev == "FL" | state_abbrev == "SC" | state_abbrev == "NC" | state_abbrev == "VA"
replace party_code = 0 if party_code==100
replace party_code = 1 if party_code==200
gen extreme = abs(nominate_dim1)
gen extremedist = abs(mrp_mean112)
recode member_race (0=1) (1/3=0), gen(whitemem)
recode member_race (2/3=0), gen(blackmem)

*Figure 1a
separate nominate_dim1, by(party)
twoway (lfitci nominate_dim10 white112, acol(gs14) clcol(black)) (lfitci nominate_dim11 white112, acol(gs14) clcol(black)) (scatter nominate_dim10 white112, col(gs10)) (scatter nominate_dim11 white112, col(gs6)), graphregion(fcolor(white)) legend(off) ytitle("First Dimension DW-NOMINATE", margin(medium)) xtitle("Pct. White in District", margin(medium))

*In-text coefficient estimates surrounding Figure 1
gen white = white112/100
regress nominate_dim1 white if party == 0
regress nominate_dim1 white if party == 1

*Table 1
*note: "white" variable measured decimals for regression analyses
regress extreme c.white i.party competitive extremedist hetero south i.congress, vce(cluster bioguide_id)
regress extreme c.white##i.party competitive extremedist hetero south i.congress, vce(cluster bioguide_id)
regress extreme c.white##c.white i.party competitive extremedist hetero south i.congress, vce(cluster bioguide_id)
regress extreme c.white##c.competitive i.party extremedist hetero south i.congress, vce(cluster bioguide_id)

*Table A1 (appendix)
sum extreme white extremedist competitive hetero party south, detail

*Table A3 (appendix)
regress extreme c.white i.party winner_voteshare extremedist hetero south i.congress, vce(cluster bioguide_id)
regress extreme c.white##i.party winner_voteshare extremedist hetero south i.congress, vce(cluster bioguide_id)
regress extreme c.white##c.white i.party winner_voteshare extremedist hetero south i.congress, vce(cluster bioguide_id)
regress extreme c.white##c.winner_voteshare i.party extremedist hetero south i.congress, vce(cluster bioguide_id)

*Table A5 (appendix)
regress nominate_dim1 c.white competitive mrp_mean112 hetero south i.congress if party==1, vce(cluster bioguide_id)
regress nominate_dim1 c.white competitive mrp_mean112 hetero south i.congress if party==0, vce(cluster bioguide_id)

*Table A7 (appendix)
regress extreme c.white i.party competitive extremedist hetero south whitemem i.congress, vce(cluster bioguide_id)
regress extreme c.white##i.party competitive extremedist hetero south whitemem i.congress, vce(cluster bioguide_id)
regress extreme c.white##c.white i.party competitive extremedist hetero south whitemem i.congress, vce(cluster bioguide_id)
regress extreme c.white##c.competitive i.party extremedist hetero south whitemem i.congress, vce(cluster bioguide_id)

***************
*Senate data and code to replicate Figure 1b and Tables 2, A2, A4, A6, and A8
***************

import delimited "senate.csv", clear
gen extreme = abs(nominate_dim1)
replace party_code = 100 if party_code==328
replace party_code = 0 if party_code==100
replace party_code = 1 if party_code==200
gen extremedist = abs(mrp_estimate)
gen hetero = tw_sd
gen competitive = competitive60
recode member_race (0=1) (1/3=0), gen(whitemem)
recode member_race (2/3=0), gen(blackmem)

*Figure 1b
separate nominate_dim1, by(party)
twoway (lfitci nominate_dim10 white, acol(gs14) clcol(black)) (lfitci nominate_dim11 white, acol(gs14) clcol(black)) (scatter nominate_dim10 white, col(gs10)) (scatter nominate_dim11 white, col(gs6)), graphregion(fcolor(white)) legend(off) yscale(range(-1(0.5)1)) ylabel(-1(0.5)1) ytick(-1(0.5)1) ytitle("First Dimension DW-NOMINATE", margin(medium)) xtitle("Pct. White in State", margin(medium))

*In-text coefficient estimates surrounding Figure 1
replace white = white/100
regress nominate_dim1 white if party == 0
regress nominate_dim1 white if party == 1 

*Table 2
*note: "white" variable measured decimals for regression analyses
mixed extreme c.white i.party competitive extremedist hetero south i.congress || state_icpsr:, vce(cluster state_icpsr)
estat ic
mixed extreme c.white##i.party competitive extremedist hetero south i.congress || state_icpsr:, vce(cluster state_icpsr)
estat ic
mixed extreme c.white##c.white i.party competitive extremedist hetero south i.congress || state_icpsr:, vce(cluster state_icpsr)
estat ic
mixed extreme c.white##i.competitive i.party extremedist hetero south i.congress || state_icpsr:, vce(cluster state_icpsr)
estat ic

*Table A2 (appendix)
sum extreme white party competitive extremedist hetero south, detail

*Table A4 (appendix)
mixed extreme c.white i.party winner_voteshare extremedist hetero south i.congress || state_icpsr:, vce(cluster state_icpsr)
estat ic
mixed extreme c.white##i.party winner_voteshare extremedist hetero south i.congress || state_icpsr:, vce(cluster state_icpsr)
estat ic
mixed extreme c.white##c.white i.party winner_voteshare extremedist hetero south i.congress || state_icpsr:, vce(cluster state_icpsr)
estat ic
mixed extreme c.white##c.winner_voteshare i.party extremedist hetero south i.congress || state_icpsr:, vce(cluster state_icpsr)
estat ic

*Table A4 (appendix)
mixed nominate_dim1 c.white competitive mrp_estimate hetero south i.congress if party==1 || state_icpsr:, vce(cluster state_icpsr)
estat ic
mixed nominate_dim1 c.white competitive mrp_estimate hetero south i.congress if party==0 || state_icpsr:, vce(cluster state_icpsr)
estat ic


*Table A6 (appendix)
mixed extreme c.white i.party competitive extremedist hetero south whitemem i.congress || state_icpsr:, vce(cluster state_icpsr)
estat ic
mixed extreme c.white##i.party competitive extremedist hetero south whitemem i.congress || state_icpsr:, vce(cluster state_icpsr)
estat ic
mixed extreme c.white##c.white i.party competitive extremedist hetero south whitemem i.congress || state_icpsr:, vce(cluster state_icpsr)
estat ic
mixed extreme c.white##i.competitive i.party extremedist hetero south whitemem i.congress || state_icpsr:, vce(cluster state_icpsr)
estat ic

*********
*Redistricting data and code to replicate Figure 2 and Tables A9 and A10
*********

import delimited "redistricting.csv", clear
gen extreme12 = abs(nokken_dim1_112)
gen extreme13 = abs(nokken_dim1_113)
gen delta_extreme = extreme13 - extreme12
gen delta_hetero = heterogeneitysd113 - heterogeneitysd112
gen gop = 1 if party_code==200
replace gop = 0 if party_code==100
gen mrp12=abs(mrp_mean112)
gen mrp13=abs(mrp_mean113)
gen delta_mrp = mrp13 - mrp12
gen delta_white = white113/100 - white112/100
gen south = 0
replace south = 1 if state_abbrev == "AR" | state_abbrev == "TX" | state_abbrev == "LA" | state_abbrev == "MS" | state_abbrev == "AL" | state_abbrev == "TN" | state_abbrev == "GA" | state_abbrev == "FL" | state_abbrev == "SC" | state_abbrev == "NC" | state_abbrev == "VA"
gen delta_competitive = competitive113 - competitive112

*Figure 2
gen where = -0.1
gen pipe = "|"
gen dwhite = delta_white*100
regress delta_extreme dwhite gop delta_mrp delta_hetero delta_competitive south
margins, at(dwhite=(-50(25)50) gop=0 south=0 delta_competitive=0) atmeans
marginsplot, recast(line) recastci(rarea) yline(0, lcol(black))  plotopts(lcol(black)) ciopts(col(gs8)) addplot(scatter where dwhite, ms(none) mlabel(pipe) mlabpos(0) mlabcolor(gs0)  xscale(range(-50(25)50)) xlabel(-50(25)50) xtick(-50(25)50) xtitle("Change in Pct. White", margin(medium)) ytitle("Change in Member Extremity", margin(medium))) legend(off) graphregion(fcolor(white)) title(" ")

*Table A9 (appendix)
regress delta_extreme delta_white 
regress delta_extreme delta_white gop delta_mrp delta_hetero delta_competitive south 

*Table A10 (appendix)
regress delta_extreme delta_white primary_comp  gop delta_mrp delta_hetero delta_competitive south 
regress delta_extreme delta_white primary_share  gop delta_mrp delta_hetero delta_competitive south 


*********
*Elections data and code to replicate Figure 3 and Tables 3, A11, A12, and A14
*********

import excel "election.xlsx", sheet("Sheet1") firstrow clear
gen extreme = .
replace extreme = recipient_cfscore if party=="R"
replace extreme = (recipient_cfscore*-1) if party=="D"
gen contest = mergecode
gen incumbent = 0
replace incumbent = 1 if Incum_Chall == "I"
gen presmargin = .
replace presmargin = dem_pres_vs if party == "D"
replace presmargin = 1-dem_pres_vs if party == "R"
gen third = 0
replace third = 1 if party == "I"
gen receipts = ln(total_receipts)
replace white = white/100
encode district, gen(distid)
gen gop = 0 if party == "D"
replace gop = 1 if party == "R"
replace gop = . if party == "I"
recode year (2010=1) (2014=1) (*=0), gen(midterm)
gen gwin = .
replace gwin = 0 if gwinner == "L"
replace gwin = 1 if gwinner == "W"
replace gwin = . if gpct ==.
recode racefh (0=1) (1/4=0) (*=.), gen(candwhite)
destring comp, gen(competitive)
replace competitive = . if gpct == .

*Table 3
mixed gpct c.extreme##c.white incumbent presmargin receipts i.gop##i.midterm i.year || contest:, vce(cluster contest)
estat ic
melogit gwin c.extreme##c.white incumbent presmargin receipts i.gop##midterm i.year || contest:, vce(cluster contest)
estat ic

*Figure 3
gen white100=white*100
mixed gpct c.extreme##c.white100 incumbent presmargin receipts i.gop##i.midterm i.year || contest:, vce(cluster contest)
margins, dydx(extreme) at(white100=(0(20)100) incumbent=1 gop=0 midterm=0 year=2012) atmeans
marginsplot, recast(line) recastci(rarea) yline(0, lcolor(black)) plotop(lcolor(black)) ciop(color(gs10)) graphregion(fcolor(white)) legend(off) xtitle("Pct. White", margin(medsmall)) title("") ytitle("Marginal Effect of Extremity on Vote Share", margin(medsmall)) xlabel(0 20 40 60 80 100)

*Table A11
sum gpct gwin extreme white incumbent presmargin receipts gop competitive, detail

*Table A12 (appendix)
mixed gpct c.extreme##c.white incumbent presmargin receipts i.gop##i.midterm candwhite i.year || contest:, vce(cluster contest)
estat ic
melogit gwin c.extreme##c.white incumbent presmargin receipts i.gop##midterm candwhite i.year || contest:, vce(cluster contest)
estat ic

*Table A14 (appendix)
melogit gwin c.extreme##c.white##i.competitive incumbent presmargin receipts i.gop##midterm i.year || contest:, vce(cluster contest)
estat ic

**********
*Elections data and code to replicate Table A13
**********

import delimited "relative_extremity.csv", clear
replace white = white/100
gen gwin = .
replace gwin = 0 if gwinner == "L"
replace gwin = 1 if gwinner == "W"

regress gpct c.relextreme##c.white dem_pres_vs relspendln deminc third i.year
estat ic
logit gwin c.relextreme##c.white dem_pres_vs relspendln deminc third i.year
estat ic